import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
import *as cc from "cc";

@ccclass('Tips')
export class Tips extends Component {
  @property(cc.Label)
  tipsString: cc.Label = null;

  setSting(label) {
    this.tipsString.string = label;
  }

  protected start(): void {
    cc.tween(this.node.getComponent(cc.UIOpacity)).to(1.5, { opacity: 0 }).start()
    cc.tween(this.node)
      .to(3, { position: cc.v3(0, this.node.getPosition().y += 800, 0) })
      .call(() => {
        this.node.removeFromParent();
        this.node.destroy();
      }).start();
  }

}


export function showTips(title: string) {
  cc.resources.load('prefabs/Home/Tips', (err, prefab: cc.Prefab) => {
    if (err) {
      console.error(err)
      return;
    }
    if (prefab) {
      let tipsNode = cc.instantiate(prefab);
      tipsNode.setParent(cc.find('Canvas', cc.director.getScene()));
      tipsNode.getComponent(Tips).setSting(title);
    }
  })
}